export const cacheKey = "localStorage";
// export const cacheKey = 'sessionStorage';
export const tokenKey = "X-Authorization";

export function getToken() {
    return window[cacheKey].getItem(tokenKey) || "";
}
export function removeToken() {
    window[cacheKey].removeItem(tokenKey);
}
export function setToken(token) {
    window[cacheKey].setItem(tokenKey, token);
    return getToken();
}

export function getCache(key, type) {
    let val = window[cacheKey].getItem(key);
    if (type === "json") {
        return JSON.parse(val || "{}");
    } else {
        return val;
    }
}
export function setCache(key, value) {
    if (typeof val !== "string") {
        value = JSON.stringify(value);
    }
    window[cacheKey].setItem(key, value);
    return getCache(key);
}